/**
 * 
 */
package com.sun.java.networking;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @author Jun
 *
 */
public class EchoClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		// TODO 自动生成方法存根

		Socket echoSocket = null;
		PrintWriter out = null;
		BufferedReader in = null;
		
		try {
			echoSocket = new Socket("taranis",7);
			out = new PrintWriter(echoSocket.getOutputStream(), true);
			in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
		} catch (UnknownHostException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String userInput;
		
		while((userInput = stdIn.readLine())!= null){
			out.println(userInput);
			System.out.println("echo:"+ in.readLine());
		}
		out.close();
		in.close();
		stdIn.close();
		echoSocket.close();
	}

}
